var concat = exports.concat = function(iterations, appendShort) {
  var string = '',
      toAppend = appendShort ? 'short' : 'some long string we should append to the base string to make it really really really really really really long';
  
  var start = Date.now();
  for (var i = 0; i < iterations; ++i) {
    string += toAppend;
  }
  var time = Date.now() - start;
  return ('Method: String concatenation; ' +
         'Iterations: ' + iterations + '; ' +
         'Length: ' + (appendShort ? 'short' : 'long') + '\n' +
         'Time: ' + time);
};

var sb_push = exports.sb_push = function(iterations, appendShort) {
  var sbuilder = [],
      toAppend = appendShort ? 'short' : 'some long string we should append to the base string to make it really really really really really really long';
  
  var start = Date.now();
  for (var i = 0; i < iterations; ++i) {
    sbuilder.push(toAppend);
  }
  var string = sbuilder.join(''),
      time = Date.now() - start;

  return ('Method: Array push; ' +
         'Iterations: ' + iterations + '; ' +
         'Length: ' + (appendShort ? 'short' : 'long') + '\n' +
         'Time: ' + time);
};

var sb_assign = exports.sb_assign = function(iterations, appendShort) {
  var sbuilder = [],
      toAppend = appendShort ? 'short' : 'some long string we should append to the base string to make it really really really really really really long';
  
  var start = Date.now();
  for (var i = 0; i < iterations; ++i) {
    sbuilder[i] = toAppend;
  }
  var string = sbuilder.join(''),
      time = Date.now() - start;

  return ('Method: Array assignment; ' +
         'Iterations: ' + iterations + '; ' +
         'Length: ' + (appendShort ? 'short' : 'long') + '\n' +
         'Time: ' + time);
};

var test = exports.test = function(iterations, appendShort) {
  if (iterations <= 100000) {
    spawn(function() {
      print(concat(iterations, appendShort));
    });
  }
  
  spawn(function() {
    print(sb_push(iterations, appendShort));
  });
  spawn(function() {
    print(sb_assign(iterations, appendShort));
  });
};

var run = exports.run = function() {
  test(5, true);
  test(5, false);
  
  test(100, true);
  test(100, false);
  
  test(100000, true);
  test(100000, false);
};